<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->

    <el-card>
      <!-- 订单列表数据 -->
      <div class="inputtop">
        <el-input placeholder="请输入订单编号" v-model="queryInfo.query">
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="getOrderList"
          ></el-button>
        </el-input>
      </div>
      <!-- 请输入内容区域 -->

      <!-- 表格区域 -->
      <el-table :data="orderList" border>
        <el-table-column type="index" class="boxx"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'">
              已付款
            </el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间" prop="create_time">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <!-- 详细地址的选择 -->
            <el-button
              type="primary"
              icon="el-icon-edit"
              @click="btn"
            ></el-button>
            <!-- 地址位置的查询 -->
            <el-button
              type="success"
              icon="el-icon-location"
              @click="btnaddress"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->

      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[5, 10, 15]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>

      <!-- 对话框区域 -->
      <el-dialog title="修改地址" :visible.sync="addressVisible" width="50%">
        <el-form
          :model="addressForm"
          status-icon
          :rules="addressFormRules"
          ref="addressFormRef"
          label-width="100px"
        >
          <el-form-item label="省市区/县" prop="address1">
            <el-cascader
              :options="cityData"
              v-model="addressForm.address1"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input
              v-model="addressForm.address2"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible">取 消</el-button>
          <el-button type="primary" @click="dialogVisible">确 定</el-button>
        </span>
      </el-dialog>

      <!-- 查询物流信息 -->
      <el-dialog
        title="您的物流信息"
        :visible.sync="dialogVisibleadd"
        width="45%"
      >
        <!-- 物流信息 -->
        <el-timeline :reverse="reverse">
          <el-timeline-item
            v-for="(activity, index) in activities"
            :key="index"
            :timestamp="activity.timestamp"
          >
            {{ activity.content }}
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import cityData from './citydata'
export default {
  data() {
    return {
      reverse: true,
      activities: [
        {
          content: '已签收,感谢使用顺丰,期待再次为您服务',
          timestamp: '2018-04-19'
        },
        {
          content:
            '[北京市]北京海淀育新小区营业点派件员 顺丰速运 95338正在为您派件',
          timestamp: '2018-04-18'
        },
        {
          content:
            '快件在[北京顺义集散中心]已装车,准备发往 [北京海淀育新小区营业点]',
          timestamp: '2018-04-18'
        },
        {
          content: '已经到达华东转用中心',
          timestamp: '2018-04-17'
        },
        {
          content: '华东业务部已经收件',
          timestamp: '2018-04-17'
        },
        {
          content: '商家已经发货,等待顺丰快递员取件',
          timestamp: '2018-04-16'
        },

        {
          content: '你的订单已经打包完成',
          timestamp: '2018-04-16'
        },
        {
          content: '您的订单开始进行拣货',
          timestamp: '2018-04-15'
        },
        {
          content: '订单确认,已经为您进行配货',
          timestamp: '2018-04-13'
        },
        {
          content: '你已提交订单,等待系统进行确认',
          timestamp: '2018-04-11'
        }
      ],
      dialogVisibleadd: false,
      addressForm: {
        address1: [],
        address2: ''
      },
      addressFormRules: {
        address1: [
          {
            required: true,
            message: '请选择省市区/县',
            trigger: 'blur'
          }
        ],
        address2: [
          {
            required: true,
            message: '请填写详细地址',
            trigger: 'blur'
          }
        ]
      },
      cityData: cityData,
      progressVisible: false,
      addressVisible: false,
      progressInfo: [],

      queryInfo: {
        query: '', //查询参数
        pagenum: 1, //当前页码
        pagesize: 5 //每页显示条数
      },
      total: 0, //代表总数据条数
      orderList: [] //代表数据是空数组
    }
  },
  created() {
    this.getOrderList() //获取当前的订单列表
  },
  methods: {
    //发起一个get请求,
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      console.log(res)
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败')
      }

      this.total = res.data.total
      this.orderList = res.data.goods
    },
    dialogVisible() {
      this.addressVisible = false
      this.addressForm.address1 = ''
      this.addressForm.address2 = ''
    },
    //修改当前地址

    //物流信息的查询
    btnaddress() {
      this.dialogVisibleadd = true
    },

    //展示修改地址的对话框
    btn() {
      this.addressVisible = true
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrderList()
    }
  }
}
</script>

<style lang="less" scoped>
.from {
  border-top: 1px solid red;
}
.inputtop {
  width: 33%;
}
.el-cascader {
  width: 100%;
}
</style>
